from pyspark import SparkFiles

from com.zsw.config.SparkBase import SparkBase


class CSVReader:
    def __init__(self, path, options=None):
        self.path = path
        self.options = options or {
            "header": "true",
            "inferSchema": "true",
            "sep": ","
        }

    def read(self):
        spark = SparkBase.get_spark()
        return spark.read \
            .format("csv") \
            .options(**self.options) \
            .load(self.path)